package com.study.casedemo;

import java.util.Random;

public class Demo3 {
    public static void main(String[] args) {
        // 案例3：生成5位数的验证码，其中可以包括数字大写字母小写字母
        for (int i = 0; i < 10; i++) {
            String s = codePr(5);
            System.out.println(s);

        }
    }
    public static String codePr(int number){
        String code = "";
        Random rd = new Random();
        for (int i = 0; i < number; i++) {
            int nextInt = rd.nextInt(3);
            switch (nextInt){
                case 0:
                    code += (char)(rd.nextInt(26)+65);
                    break;
                case 1:
                    code += (char)(rd.nextInt(26)+97);
                    break;
                case 2:
                    code += rd.nextInt(10);
                    break;
            }
        }
        return code;
    }
}
